package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by v on 17-4-11.
 *
 * 对于已经登录的用户，将不再显示登录界面，直接放行
 */
@WebFilter(filterName = "FilterForm",value = "/testjsp/4.11/form.html")
public class FilterForm implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request=(HttpServletRequest) servletRequest;
        HttpServletResponse response=(HttpServletResponse) servletResponse;

        if(request.getSession().getAttribute(request.getRemoteAddr())!=null){
            response.sendRedirect("/testjsp/4.11/logIn.html");
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
